home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / MACRO.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  13KB  |  462 lines

  1. ;***********************;
  2. ; SESSION Macro Support ;
  3. ;     By Eric Tauck     ;
  4. ;***********************;
  5.  
  6. m_run   DB      'Macro file to execute: ', 0
  7.  
  8. m_err1  DB      'Not enough memory',0
  9. m_err2  DB      'Out of symbol space',0
  10. m_err3  DB      'Out of code space',0
  11. m_err4  DB      'Token too long',0
  12. m_err5  DB      'Undefined symbol',0
  13. m_err6  DB      'Unexpected end of macro file',0
  14. m_err7  DB      'Unable to read macro file',0
  15. m_err8  DB      'Invalid number after ALLOC',0
  16. m_err9  DB      'Undefined symbol: ',0
  17.  
  18. m_errs  DW      OFFSET m_err1, OFFSET m_err2, OFFSET m_err3, OFFSET m_err4
  19.         DW      OFFSET m_err5, OFFSET m_err6, OFFSET m_err7, OFFSET m_err8
  20.  
  21. m_nl    DB      13, 10, 0
  22.  
  23. ;--- user defined words
  24.  
  25. MacUsr  LABEL   BYTE
  26.         DB      'CGET',0, OFFSET Macro_CGET
  27.         DB      'CPUT',0, OFFSET Macro_CPUT
  28.         DB      'CREP',0, OFFSET Macro_CREP
  29.         DB      'KGET',0, OFFSET Macro_KGET
  30.         DB      'KREP',0, OFFSET Macro_KREP
  31.         DB      'TERM',0, OFFSET Macro_TERM
  32.         DB      'RESET',0, OFFSET Macro_RESET
  33.         DB      'TICKS',0, OFFSET Macro_TICKS
  34.         DB      'CLEAR',0, OFFSET Macro_CLEAR
  35.         DB      'TYPE',0, OFFSET Macro_TYPE
  36.         DB      'MESS',0, OFFSET Macro_MESS
  37.         DB      'ERROR',0, OFFSET Macro_ERROR
  38.         DB      'INPUT',0, OFFSET Macro_INPUT
  39.         DB      'VERIFY',0, OFFSET Macro_VERIFY
  40.         DB      'ULOAD',0, OFFSET Macro_ULOAD
  41.         DB      'DLOAD',0, OFFSET Macro_DLOAD
  42.         DB      0
  43.  
  44. ;========================================
  45. ; Load and compile a macro.
  46. ;
  47. ; In: AX= file name or 0 if none.
  48. ;
  49. ; Out: CY= set if abort.
  50.  
  51. Macro_Load PROC NEAR
  52.         push    di
  53.         StkAll  di, 80          ;allocate space for file name and error mess.
  54.  
  55. ;--- input file name
  56.  
  57.         or      ax, ax          ;check if name passed
  58.         jz      macloa1         ;jump if not
  59.         mov     bx, di
  60.         call    StrCpy          ;copy to buffer
  61.         jmps    macloa2
  62.         
  63. macloa1 mov     ax,OFFSET t_rea ;prompt
  64.  
  65.         mov     ax,OFFSET m_run ;prompt
  66.         mov     bx, di          ;storage for file name
  67.         call    Command_Input   ;input a file name
  68.         jc      macloa7         ;jump if cancel
  69.  
  70. ;---- check if file exists, if not, try using program path
  71.  
  72. macloa2 mov     ax, di
  73.         call    Find_File       ;find file
  74.         jnc     macloa3         ;jump if found
  75.         mov     ax, di
  76.         call    Cut_Name        ;check if drive or directory
  77.         jnc     macloa3         ;jump if so, let MacCom handle it
  78.         call    EnvPro          ;get program name
  79.         jc      macloa3         ;jump if can't, let MacCom handle it
  80.  
  81.         push    si
  82.         StkAll  si, 80
  83.         mov     cx, ds
  84.         mov     bx, si
  85.         call    StrCpyF         ;program name to local storage
  86.         mov     ax, si
  87.         call    Cut_Name        ;find end of path
  88.         mov     bx, ax
  89.         mov     ax, di
  90.         call    StrCpy          ;append to end of path
  91.         mov     ax, si
  92.         mov     bx, di
  93.         call    StrCpy          ;copy to input buffer
  94.         StkRel  80
  95.         pop     si
  96.  
  97. ;---- compile and load
  98.  
  99. macloa3 mov     ax, di
  100.         call    MacCom          ;compile and load macro
  101.         jc      macloa4         ;jump if error
  102.  
  103.         StkRel  80
  104.         pop     di
  105.         clc
  106.         ret
  107.  
  108. ;--- deal with error
  109.  
  110. macloa4 mov     bx, ax
  111.         dec     bx
  112.         shl     bx
  113.         cmp     ax, MACRO_UNDEF         ;check if undefined symbol
  114.         jne     macloa5                 ;skip if not
  115.  
  116.         push    bx
  117.         mov     ax, OFFSET m_err9
  118.         mov     bx, di
  119.         call    StrCpy                  ;copy error message
  120.         add     ax, di                  ;end of error message
  121.         call    MacUnd                  ;append symbol
  122.         mov     ax, di
  123.         pop     bx
  124.         jnc     macloa6                 ;jump if okay
  125.  
  126. macloa5 mov     ax, [m_errs + bx]       ;load error message
  127. macloa6 call    Command_Error           ;display
  128.  
  129. macloa7 StkRel  80
  130.         pop     di
  131.         stc
  132.         ret
  133.         ENDP
  134.  
  135. ;========================================
  136. ; Return the end of the drive/directory
  137. ; of a file name.
  138. ;
  139. ; In: AX= file name.
  140. ;
  141. ; Out: AX= first byte of filename (byte
  142. ;      after drive and path); CY= set if
  143. ;      no drive/path.
  144.  
  145. Cut_Name PROC   NEAR
  146.         push    si
  147.         mov     si, ax
  148.         mov     bx, ax
  149.         mov     cx, ax
  150.         cld
  151.  
  152. cutnam1 lodsb                   ;load byte
  153.         or      al, al          ;check if end of string
  154.         jz      cutnam3
  155.         cmp     al, ':'         ;check if drive specifier
  156.         je      cutnam2
  157.         cmp     al, '\'         ;check if directory specifier
  158.         jne     cutnam1
  159. cutnam2 mov     bx, si          ;save this location
  160.         jmps    cutnam1
  161.  
  162. cutnam3 mov     ax, bx
  163.         pop     si
  164.         sub     cx, bx          ;set carry if found
  165.         cmc                     ;set carry if not found
  166.         ret
  167.         ENDP
  168.  
  169. ;========================================
  170. ; Get a serial byte. Return FALSE if not
  171. ; available or TRUE and the value if
  172. ; available.
  173.  
  174. Macro_CGET PROC  FAR
  175.  
  176. ;--- read terminal byte buffer
  177.  
  178.         mov     al, t_cflg      ;load flag
  179.         or      al, al          ;check if set
  180.         jz      macget2         ;jump if not
  181.  
  182.         dec     t_cflg          ;zero flag
  183.         mov     al, t_cbyt      ;load data byte
  184.  
  185. ;--- return TRUE and a value
  186.  
  187. macget1 sub     ah, ah
  188.         call    MacSto          ;store byte
  189.         mov     ax, -1
  190.         call    MacSto          ;store flag
  191.         ret
  192.  
  193. ;--- check serial port directly
  194.  
  195. macget2 mov     bx, t_ser
  196.         call    ComGet          ;try getting byte directly
  197.         jnc     macget1
  198.  
  199. ;--- return FALSE and no byte
  200.  
  201.         sub     ax, ax
  202.         call    MacSto          ;store
  203.         ret
  204.         ENDP
  205.  
  206. ;========================================
  207. ; Send a byte directly to the serial
  208. ; port.
  209.  
  210. Macro_CPUT PROC  FAR
  211.         call    MacLoa          ;load byte
  212.         mov     bx, t_ser
  213.         call    ComPut          ;send it
  214.         ret
  215.         ENDP
  216.  
  217. ;========================================
  218. ; Replace a serial byte.
  219.  
  220. Macro_CREP PROC  FAR
  221.         call    MacLoa          ;get byte
  222.         mov     t_cflg, 1       ;set flag
  223.         mov     t_cbyt, al      ;store value
  224.         ret
  225.         ENDP
  226.  
  227. ;========================================
  228. ; Get a keystroke. Return FALSE if not
  229. ; available or TRUE and the value if
  230. ; available.
  231.  
  232. Macro_KGET PROC  FAR
  233.  
  234. ;--- read buffer
  235.  
  236.         mov     al, t_kflg      ;load flag
  237.         or      al, al          ;check if set
  238.         jz      macgek2         ;jump if not
  239.  
  240.         dec     t_kflg          ;zero flag
  241.         mov     ax, t_kbyt      ;load data byte
  242.  
  243. ;--- return TRUE and a value
  244.  
  245. macgek1 call    MacSto          ;store key
  246.         mov     ax, -1
  247.         call    MacSto          ;store flag
  248.         ret
  249.  
  250. ;--- check keyboard directly
  251.  
  252. macgek2 call    KeyGet          ;get keystroke
  253.         jnc     macgek1
  254.  
  255. ;--- return FALSE and no byte
  256.  
  257.         sub     ax, ax          ;return false
  258.         call    MacSto
  259.         ret
  260.         ENDP
  261.  
  262. ;========================================
  263. ; Replace a keystroke.
  264.  
  265. Macro_KREP PROC  FAR
  266.         call    MacLoa          ;get key
  267.         mov     t_kflg, 1       ;set flag
  268.         mov     t_kbyt, ax      ;store value
  269.         ret
  270.         ENDP
  271.  
  272. ;========================================
  273. ; Send a byte through the terminal.
  274.  
  275. Macro_TERM PROC FAR
  276.         call    MacLoa          ;get byte
  277.         call    Term_Out        ;terminal output
  278.         ret
  279.         ENDP
  280.  
  281. ;========================================
  282. ; Reset timer.
  283.  
  284. Macro_RESET PROC FAR
  285.         mov     al, MACRO_TIMER
  286.         call    TicRes          ;reset timer
  287.         ret
  288.         ENDP
  289.  
  290. ;========================================
  291. ; Return timer ticks passed.
  292.  
  293. Macro_TICKS PROC FAR
  294.         mov     al, MACRO_TIMER
  295.         call    TicPas          ;get ticks passed
  296.         call    MacSto          ;store ticks
  297.         ret
  298.         ENDP
  299.  
  300. ;========================================
  301. ; Clear both windows.
  302.  
  303. Macro_CLEAR PROC FAR
  304.         call    Clear_Both
  305.         ret
  306.         ENDP
  307.  
  308. ;========================================
  309. ; Type a system character.
  310.  
  311. Macro_TYPE PROC FAR
  312.         push    di
  313.         StkAll  di, 2           ;allocate local storage
  314.         call    MacLoa          ;load character
  315.         sub     ah, ah          ;NUL
  316.         mov     [di], ax        ;store character and NUL
  317.         mov     ax, di
  318.         call    System_String   ;display as string
  319.         StkRel  2               ;fix stack
  320.         pop     di
  321.         ret
  322.         ENDP
  323.  
  324. ;========================================
  325. ; Display a system message.
  326.  
  327. Macro_MESS PROC FAR
  328.         push    di
  329.         StkAll  di, 80          ;allocate local storage
  330.         call    MacLoa          ;load address
  331.         mov     cx, ds
  332.         mov     bx, di
  333.         call    StrCpyF         ;copy to local storage
  334.         mov     ax, di
  335.         call    System_String   ;display
  336.         mov     ax, OFFSET m_nl
  337.         call    System_String   ;display new line
  338.         StkRel  80              ;fix stack
  339.         pop     di
  340.         ret
  341.         ENDP
  342.  
  343. ;========================================
  344. ; Display an error.
  345.  
  346. Macro_ERROR PROC FAR
  347.         push    di
  348.         StkAll  di, 80          ;allocate local storage
  349.         call    MacLoa          ;load address
  350.         mov     cx, ds
  351.         mov     bx, di
  352.         call    StrCpyF         ;copy to string to local storage
  353.         mov     ax, di
  354.         call    Command_Error   ;display
  355.         StkRel  80              ;fix stack
  356.         pop     di
  357.         ret
  358.         ENDP
  359.  
  360. ;========================================
  361. ; Perform a verify.
  362.  
  363. Macro_VERIFY PROC FAR
  364.         push    di
  365.         StkAll  di, 80          ;prompt storage
  366.         call    MacLoa          ;get address
  367.         mov     cx, ds
  368.         mov     bx, di
  369.         call    StrCpyF         ;copy prompt to local storage
  370.         mov     ax, di
  371.         call    Command_Confirm ;verify
  372.         mov     ax, 0           ;return value
  373.         jc      macver1         ;jump if not verified
  374.         dec     ax              ;return TRUE
  375. macver1 call    MacSto          ;store flag
  376.         StkRel  80
  377.         pop     di
  378.         ret
  379.         ENDP
  380.  
  381. ;========================================
  382. ; Input a string.
  383.  
  384. Macro_INPUT PROC FAR
  385.         push    di
  386.         push    si
  387.         StkAll  di, 80          ;prompt storage
  388.         StkAll  si, 80          ;allocate temporary input buffer
  389.         call    MacLoa          ;load address
  390.         mov     cx, ds
  391.         mov     bx, di
  392.         call    StrCpyF         ;copy prompt to local storage
  393.         mov     ax, di
  394.         mov     bx, si
  395.         call    Command_Input   ;input string
  396.         mov     ax, 0
  397.         jc      macinp1         ;jump if no input
  398.         dec     ax
  399. macinp1 push    ax
  400.         call    MacLoa          ;get buffer address
  401.         mov     cx, dx
  402.         mov     bx, ax
  403.         pop     ax
  404.  
  405.         or      ax, ax
  406.         jz      macinp2
  407.         push    ax
  408.         mov     dx, ds
  409.         mov     ax, si
  410.         call    StrCpyF         ;copy to macro area
  411.         pop     ax
  412.  
  413. macinp2 call    MacSto          ;store flag
  414.  
  415.         StkRel  80 + 80         ;fix stack
  416.         pop     si
  417.         pop     di
  418.         ret
  419.         ENDP
  420.  
  421. ;========================================
  422. ; Upload a file.
  423.  
  424. Macro_ULOAD PROC FAR
  425.         push    di
  426.         push    si
  427.         StkAll  si, 80          ;allocate local storage
  428.         call    MacLoa          ;load file address
  429.         mov     cx, ds
  430.         mov     bx, si
  431.         call    StrCpyF         ;copy to name to local storage
  432.         call    Xmodem_Flags    ;set flags
  433.         mov     ax, si
  434.         mov     bx, t_ser
  435.         call    Xmodem_Upload   ;perform upload
  436.         StkRel  80              ;fix stack
  437.         pop     si
  438.         pop     di
  439.         ret
  440.         ENDP
  441.  
  442. ;========================================
  443. ; Download a file.
  444.  
  445. Macro_DLOAD PROC FAR
  446.         push    di
  447.         push    si
  448.         StkAll  si, 80          ;allocate local storage
  449.         call    MacLoa          ;load file address
  450.         mov     cx, ds
  451.         mov     bx, si
  452.         call    StrCpyF         ;copy to name to local storage
  453.         call    Xmodem_Flags    ;set flags
  454.         mov     ax, si
  455.         mov     bx, t_ser
  456.         call    Xmodem_Download ;perform download
  457.         StkRel  80              ;fix stack
  458.         pop     si
  459.         pop     di
  460.         ret
  461.         ENDP
  462.